#include <cstdlib>
#include <iostream>
#include <fstream>

bool fileExists(const std::string& path) {
    std::ifstream f(path);
    return f.good();
}

void play_music() {
    const std::string ffplayPath = "src\\music\\ffmpeg\\bin\\ffplay.exe";
    const std::string audioPath = "src\\music\\example1.mp3";
    
    if (!fileExists(ffplayPath)) {
        std::cerr << "Error: " << ffplayPath << " not found!" << std::endl;
        return ;
    }
    
    if (!fileExists(audioPath)) {
        std::cerr << "Error: " << audioPath << " not found!" << std::endl;
        return ;
    }

    // 构建命令（使用正斜杠更通用）
    std::string command = ffplayPath + " -nodisp -autoexit " + audioPath;
    std::cout << "Executing: " << command << std::endl;

    // 执行命令
    if (system(command.c_str()) == 0) {
        std::cout<<std::endl;
    } else {
        std::cerr << "Failed to play sound. Error code: " << errno << std::endl;
    }

    return ;
}